import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'count_controller.dart';

class TargetPage extends StatefulWidget {
  const TargetPage({Key key}) : super(key: key);

  @override
  _TargetPageState createState() => _TargetPageState();
}

class _TargetPageState extends State<TargetPage> {
  int count = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("子页面"),
      ),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        child: Column(
          children: [
            Text("$count"),
            ElevatedButton(
              child: Text("setSate计数器"),
              onPressed: () {
                setState(() {
                  count++;
                });
              },
            ),
            GetBuilder(
              init: CountController(),
              builder: (CountController controller) {
                return Text("${controller.count}");
              },
            ),
            ElevatedButton(
              child: Text("getX计数器"),
              onPressed: () {
                Get.find<CountController>().add();
              },
            ),
            GetBuilder(
              init: CountController(),
              id: '_count2',
              builder: (CountController controller) {
                return Text("${controller.count2}");
              },
            ),
            ElevatedButton(
              child: Text("getX计数器局部更新--局部更新"),
              onPressed: () {
                Get.find<CountController>().addCount2();
              },
            ),
            GetX<CountController>(
              init: CountController(),
              builder: (CountController controller) {
                return Text("${controller.count3}");
              },
            ),
            Obx(() {
              return Text("Obx当前的值 ${Get.find<CountController>().count3}");
            }),
            ElevatedButton(
              child: Text("getX计数器局部更新--响应式编程"),
              onPressed: () {
                Get.find<CountController>().addCount3();
              },
            ),
          ],
        ),
      ),
    );
  }
}
